package com.ruoyi.framework.config;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;

/**
 * 配置默认事务
 * @author xianz
 *
 */
@Configuration
@EnableTransactionManagement
public class TransactionManagementConfig implements TransactionManagementConfigurer{

	@Resource(name="mybatisTransactionManager")
	private PlatformTransactionManager platformTransactionManager;
	
	@Override
	public PlatformTransactionManager annotationDrivenTransactionManager() {
		return platformTransactionManager;
	}
	
	
    @Bean("mybatisTransactionManager")
    public PlatformTransactionManager mybatisTransactionManager(DataSource  dataSource ) {
    	DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(dataSource);
        return dataSourceTransactionManager;
    }

}
